package demo.practice.leetcode_msjd;

import java.util.Arrays;

public class Msjd0102 {

    public static void main(String[] args) {
        Msjd0102 msjd0102 = new Msjd0102();
        msjd0102.CheckPermutation("abc", "bca");
    }

    public boolean CheckPermutation(String s1, String s2) {
       if (s1 == null || s2 == null)
            return s1 == s2;

        if (s1.length() != s2.length())
            return false;

        char[] chars1 = s1.toCharArray();
        char[] chars2 = s2.toCharArray();
        Arrays.sort(chars1);
        Arrays.sort(chars2);

        return Arrays.equals(chars1,chars2);



        /*
        int[] a1 = new int[26];
        int[] a2 = new int[26];
        for (int i = 0; i < s1.length(); i++) {
            a1[s1.charAt(i) - 'a']++;
            a2[s2.charAt(i) - 'a']++;
        }

        for (int i = 0; i < s1.length(); i++) {
            if (a1[s1.charAt(i) - 'a'] != a2[s1.charAt(i) - 'a'])
                return false;
        }
        return true;*/

    }


}
